*Replicatoin file for figures and graphs of "Beyond Democracy-Dictatorship Measures", April 16, 2018
* Based on v 7.1 of the merged contemporary and historical V-Dem data
use "/Users/svet-jte/Dropbox/Structure of executives/PoP Accepted/replication of descriptives data.dta", clear

* DESCRIPTVE GRAPHS
* FIGURE 1
qui xtsum mon_both_v70 if leg_rule2<. & op_both_v70<. & elecexw<.
gen sd_b=`r(sd_b)'
gen sd_w=`r(sd_w)'
local Tbar=round(`r(Tbar)',0.1)
graph hbar mon_both_v70 sd_b sd_w, ylabel(#11) yscale(r(0 1)) ytitle("") legend(order(1 "Mean" 2 "Between-std.dev." 3 "Within-std.dev") rows(1)) xsize(15) title("Hereditary" /* (N=`r(N)', n=`r(n)', mean years/country=`Tbar')" */) name(monw, replace) scheme(s2mono)
qui xtsum mil_both_v70 if leg_rule2<. & op_both_v70<. & elecexw<.
replace sd_b=`r(sd_b)'
replace sd_w=`r(sd_w)'
local Tbar=round(`r(Tbar)',0.1)
graph hbar mil_both_v70 sd_b sd_w, ylabel(#11) yscale(r(0 1)) ytitle("") legend(order(1 "Mean" 2 "Between-std.dev." 3 "Within-std.dev") rows(1)) xsize(15) title("Military" /* (N=`r(N)', n=`r(n)', mean years/country=`Tbar')" */) name(milw, replace) scheme(s2mono)
qui xtsum op_both_v70 if leg_rule2<. & op_both_v70<. & elecexw<.
replace sd_b=`r(sd_b)'
replace sd_w=`r(sd_w)'
local Tbar=round(`r(Tbar)',0.1)
graph hbar op_both_v70 sd_b sd_w, ylabel(#11) yscale(r(0 1)) ytitle("") legend(order(1 "Mean" 2 "Between-std.dev." 3 "Within-std.dev") rows(1)) xsize(15) title("Ruling party" /* (N=`r(N)', n=`r(n)', mean years/country=`Tbar')" */) name(opw, replace) scheme(s2mono)
qui xtsum elecexw if leg_rule2<. & op_both_v70<. & elecexw<.
replace sd_b=`r(sd_b)'
replace sd_w=`r(sd_w)'
local Tbar=round(`r(Tbar)',0.1)
graph hbar elecexw sd_b sd_w, ylabel(#11) yscale(r(0 1)) ytitle("") legend(order(1 "Mean" 2 "Between-std.dev." 3 "Within-std.dev") rows(1)) xsize(15) title("Direct election" /* (N=`r(N)', n=`r(n)', mean years/country=`Tbar')" */) name(elecexw, replace) scheme(s2mono)
qui xtsum leg_rule2 if leg_rule2<. & op_both_v70<. & elecexw<.
replace sd_b=`r(sd_b)'
replace sd_w=`r(sd_w)'
local Tbar=round(`r(Tbar)',0.1)
graph hbar leg_rule2 sd_b sd_w, ylabel(#11) yscale(r(0 1)) ytitle("") legend(order(1 "Mean" 2 "Between-std.dev." 3 "Within-std.dev") rows(1)) xsize(20) title("Confidence" /* (N=`r(N)', n=`r(n)', mean years/country=`Tbar')" */) name(leg_rule2, replace) scheme(s2mono)
grc1leg monw milw opw elecexw leg_rule2,legendfrom(leg_rule2) cols(1) b1title("") iscale(.5)
drop sd_b sd_w
graph save Graph "$Dropbox/Structure of executives/PoP Accepted/Figure 1.pdf", replace

* FIGURE 2
gen quinc=int((year-1789)/5)
preserve
  collapse opw op_both* op_dism milw mil_both* mil_dism monw mon_both* mon_dism elecexw leg_rule* confw,by(quinc)
  gen year=1789+5*quinc
  gen max=.50
  gen other=year if year>=1945
  sum
  twoway (line mon_both_v70 year) (line mil_both_v70 year) (line op_both_v70 year) (line elecexw year) (line leg_rule2 year) ,scheme(s2mono) xline(1895(1)1900)  legend(order(1 "Hereditary" 2 "Military" 3 "Ruling party" 4 "Direct election" 5 "Confidence"))
restore
graph save Graph "$Dropbox/Structure of executives/PoP Accepted/Figure 2.pdf"

* FIGURE 3
graph hbar mon_both_v70 mil_both_v70  op_both_v70  elecexw leg_rule2 if chga_hinst==0, ylabel(#11, labs(vlarge)) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Parliamentary democracy", size(vhuge)) scheme(s2mono) name(chga0, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if chga_hinst==1, ylabel(#11, labs(vlarge)) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Semi-presidential democracy", size(vhuge)) scheme(s2mono) name(chga1, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if chga_hinst==2, ylabel(#11, labs(vlarge)) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Presidential democracy", size(vhuge)) scheme(s2mono) name(chga2, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if chga_hinst==3, ylabel(#11, labs(vlarge)) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Civilian dictatorship", size(vhuge)) scheme(s2mono) name(chga3, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if chga_hinst==4, ylabel(#11, labs(vlarge)) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Military dictatorship", size(vhuge)) scheme(s2mono) name(chga4, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if chga_hinst==5, ylabel(#11, labs(vlarge)) yscale(r(0 1)) ytitle("") legend(order(1 "Hereditary" 2 "Military" 3 "Ruling party" 4 "Direct election" 5 "Confidence") rows(1) size(medsmall) symx(*.4)) xsize(15) title("Royal dictatorship", size(vhuge)) scheme(s2mono) name(chga5, replace)
grc1leg chga0 chga1 chga2 chga3 chga4 chga5, legendfrom(chga5) cols(1) iscale(.1)
* EDITED BY HAND IN EDITORIAL EDITOR FOR VISIBILITY OF LEGENDS
graph save Graph "$Dropbox/Structure of executives/PoP Accepted/Figure 3.pdf"

* FIGURE 4
qui sum frefair if monw==1
graph hbox frefair if monw==1,/* ylabel(none)*/ yscale(r(0 1)) ytitle("") xsize(14) title("Hereditary (n=`r(N)')") name(monw, replace) scheme(s2mono) 
qui sum frefair if milw==1
graph hbox frefair if milw==1,/* ylabel(none)*/ yscale(r(0 1)) ytitle("") xsize(14) title("Military (n=`r(N)')") name(milw, replace) scheme(s2mono) 
qui sum frefair if opw==1
graph hbox frefair if opw==1, /* ylabel(none)*/ yscale(r(0 1)) ytitle("")  xsize(14) title("Ruling party (n=`r(N)')") name(opw, replace) scheme(s2mono) 
qui sum frefair if elecexw==1
graph hbox frefair if elecexw==1, /* ylabel(none)*/ yscale(r(0 1)) ytitle("")  xsize(14) title("Direct election (n=`r(N)')") name(prezw, replace) scheme(s2mono) 
qui sum frefair if confw==1
graph hbox frefair if confw==1, yscale(r(0 1)) ytitle("")  xsize(14) title("Confidence (n=`r(N)')") name(parlw, replace) scheme(s2mono) 
graph combine monw milw opw prezw parlw,cols(1) /* b1title("Latent estimate of clean elections (v2xel_frefair); n=no of elections") */ iscale(.5)
graph save Graph "$Dropbox/Structure of executives/PoP Accepted/Figure 4.pdf"

* FIGURE 5
qui sum suffr if opw==1
graph hbox suffr if opw==1,  yscale(r(0 1)) ytitle("")  xsize(14) title("Ruling party (n=`r(N)')") name(opw, replace) scheme(s2mono)
qui sum suffr if milw==1
graph hbox suffr if milw==1, yscale(r(0 1)) ytitle("") xsize(14) title("Military (n=`r(N)')") name(milw, replace) scheme(s2mono)
qui sum suffr if monw==1
graph hbox suffr if monw==1, yscale(r(0 1)) ytitle("") xsize(14) title("Hereditary (n=`r(N)')") name(monw, replace) scheme(s2mono)
qui sum suffr if elecexw==1
graph hbox suffr if elecexw==1, yscale(r(0 1)) ytitle("")  xsize(14) title("Direct election (n=`r(N)')") name(prezw, replace) scheme(s2mono)
qui sum suffr if confw==1
graph hbox suffr if confw==1,                yscale(r(0 1)) ytitle("")          xsize(14) title("Confidence (n=`r(N)')") name(parlw, replace) scheme(s2mono)
graph combine monw milw opw prezw parlw,cols(1) /* b1title("Extension of suffrage (v2x_suffr); n=no oc country-years") */ iscale(.5)
graph save Graph "$Dropbox/Structure of executives/PoP Accepted/Figure 5.pdf"

* FIGURE 6
eststo clear
set more off
reg rep mon_both_v70  mil_both_v70  op_both_v70 elecexw  leg_rule2 foreignw assw dual v2ex_hosw v2x_suffr v2xel_frefair , cluster(country_id)
eststo m1
local r2=round(e(r2),.001)
coefplot, keep (op_both_v70 mil_both_v70 mon_both_v70  elecexw  leg_rule2) xline(0) title("Cross-sectional (95 % CIs)") note("R-squared=`r2'") name(fig4a, replace) scheme(s2mono)
xtreg rep mon_both_v70  mil_both_v70  op_both_v70  elecexw  leg_rule2 foreignw assw dual v2ex_hosw  v2x_suffr v2xel_frefair i.year, fe cluster(country_id)
eststo m2
local r2=round(e(r2),.001)
coefplot, keep (op_both_v70 mil_both_v70 mon_both_v70  elecexw  leg_rule2) coeflabels(op_both_v70="                 " mil_both_v70=" " mon_both_v70=" " elecexw=" " leg_rule2=" ") xline(0) title("Fixed effects (95 % CIs)") note("R-squared (within)=`r2'") name(fig4b, replace) scheme(s2mono)
graph combine fig4a fig4b
graph save Graph "$Dropbox/Structure of executives/PoP Accepted/Figure 6.pdf"


* FIGURE 7
reg v2x_corr mon_both_v70  mil_both_v70  op_both_v70  elecexw  leg_rule2 foreignw assw dual v2ex_hosw v2x_suffr v2xel_frefair, cluster(country_id)
eststo m3
local r2=round(e(r2),.001)
coefplot, keep (op_both_v70 mil_both_v70 mon_both_v70  elecexw  leg_rule2) xline(0) title("Cross-sectional (95 % CIs)") note("R-squared=`r2'") name(fig5a, replace) scheme(s2mono)
xtreg v2x_corr mon_both_v70  mil_both_v70  op_both_v70  elecexw  leg_rule2 foreignw assw dual v2ex_hosw v2x_suffr v2xel_frefair i.year, fe cluster(country_id)
eststo m4
local r2=round(e(r2),.001)
coefplot, keep (op_both_v70 mil_both_v70 mon_both_v70  elecexw  leg_rule2) coeflabels(op_both_v70="                 " mil_both_v70=" " mon_both_v70=" " elecexw=" " leg_rule2=" ") xline(0) title("Fixed effects (95 % CIs)") note("R-squared (within)=`r2'") name(fig5b, replace) scheme(s2mono)
graph combine fig5a fig5b
graph save Graph "$Dropbox/Structure of executives/PoP Accepted/Figure 7.pdf"

* APPENDIX REGRESSION TABLE H1:
cd "$Dropbox/Structure of executives/PoP Accepted/"
esttab using "tabH1.rtf", b(3) se(3) star(* 0.10 ** 0.05 *** 0.01 ) sca("r2_a" "N" "N_clust") replace obslast label nogaps keep(mon_both_v70  mil_both_v70  op_both_v70 elecexw  leg_rule2 foreignw assw dual v2ex_hosw_rec v2x_suffr v2xel_frefair) mtitles("Repression, c-s" "Repression, f-e" "Corruption, c-s" "Corruption, f-e")

* FIGURE 8
use "$Dropbox/Structure of executives/PoP Accepted/replication of survival data.dta", clear
eststo clear
set more off
stcox mon_both_v70  mil_both_v70 op_both_v70  elecex  leg_rule2 foreign ass hos relw v2x_suffr v2xel_frefair , cluster(country_id)
eststo m1
coefplot, keep (op_both_v70 mil_both_v70 mon_both_v70  elecex  leg_rule2) eform xline(1) title("All executives") note("`e(N_sub)' subjects, `e(N_fail)' failures; n=`e(N)'; N=`e(N_clust)'") name(fig7a, replace) scheme(s2mono)
stcox mon_both_v70  mil_both_v70 op_both_v70 elecex  leg_rule2 foreign ass hos v2x_suffr v2xel_frefair if relw>0, cluster(country_id)
eststo m2
coefplot, keep (op_both_v70 mil_both_v70 mon_both_v70  elecex  leg_rule2) eform xline(1) title("Only influential executives") note("`e(N_sub)' subjects, `e(N_fail)' failures; n=`e(N)'; N=`e(N_clust)'") name(fig7b, replace) scheme(s2mono)
graph combine fig7a fig7b
* Running on 20th<. century sample only:
stcox op_both_v70 mil_both_v70 mon_both_v70  elecex  leg_rule2 foreign ass hos relw  v2x_suffr v2xel_frefair if year>1899, cluster(country_id)
eststo m3

* APPENDIX COX REGRESSION TABLE H2:
cd "$Dropbox/Structure of executives/PoP Accepted/"
esttab using "tabH2.rtf", b(3) se(3) star(* 0.10 ** 0.05 *** 0.01 ) sca("N" "N_clust" "N_sub" "N_fail") replace obslast label nogaps eform mtitles("All executives" "Influential executives" "1900< sample")



* APPENDIX GRAPHS (not made available as pdf:s)
use "/Users/svet-jte/Dropbox/Structure of executives/PoP Accepted/replication of descriptives data.dta", clear

* APPENDIX C
gen reg_1=mon
gen reg_2=mil
gen reg_3=op
gen reg_4=elecex
gen reg_6=dual
gen rule_1=mon_dism
gen rule_2=mil_dism
gen rule_3=op_dism
gen rule_5=leg_rule2
gen rule_6=v2ex_hosw
* FIGURE C1: RUSSIA
preserve
keep if country_name=="Russia"
replace reg_2=1 if year>=1917 & year<=1918
replace reg_3=0 if year>=1917 & year<=1918
replace reg_3=1 if year>=1919 & year<=1923
replace reg_6=0 if year>=1917 & year<=1920
replace rule_6=1 if year>=1917 & year<=1920
keep year reg_* rule_*
reshape long reg_ rule_,i(year) j(dim)
label var dim "Principles of executive appointment/dismissal"
label define dim 1 "Hereditary" 2 "Military" 3 "Ruling party"  4 "Direct Election" 5 "Confidence" 6 "Dual/HOS vs. HOG"
label values dim dim
label var reg_ "Appointment"
label var rule_ "Dismissal"
twoway bar reg_ year, bstyle(background) fcolor(gs8)  || line rule_ year,cmiss(n) ||,by(dim, cols(1)) ytitle("") ylabel(#2) xlabel(1790(15)2020)
restore
* FIGURE C2: GERMANY/PRUSSIA
preserve
keep if country_name=="Germany"
keep year reg_* rule_*
set obs 228
replace year=1945 in 225
replace year=1946 in 226
replace year=1947 in 227
replace year=1948 in 228
reshape long reg_ rule_,i(year) j(dim)
label var dim "Principles of executive appointment/dismissal"
label define dim 1 "Hereditary" 2 "Military" 3 "Ruling party"  4 "Direct Election" 5 "Confidence" 6 "Dual/HOS vs. HOG"
label values dim dim
label var reg_ "Appointment"
label var rule_ "Dismissal"
twoway bar reg_ year, bstyle(background) fcolor(gs8)  || line rule_ year,cmiss(n) ||,by(dim, cols(1)) ytitle("") ylabel(#2) xlabel(1790(15)2020)
restore
* FIGURE C3: EGYPT
preserve
keep if country_name=="Egypt"
replace reg_6=foreign
replace reg_6=1 if year>=1882 & year<=1900 
replace reg_2=1 if year==2013
replace rule_6=.
replace rule_5=leg_rule2 
replace rule_5=.67 if year==2012 
keep year reg_* rule_*
reshape long reg_ rule_,i(year) j(dim)
label var dim "Principles of executive appointment/dismissal"
label define dim 1 "Hereditary" 2 "Military" 3 "Ruling party"  4 "Direct Election" 5 "Confidence" 6 "Foreign power"
label values dim dim
label var reg_ "Appointment"
label var rule_ "Dismissal/control"
twoway bar reg_ year, bstyle(background) fcolor(gs8)  || line rule_ year,cmiss(n) ||,by(dim, cols(1)) ytitle("") ylabel(#2) xlabel(1790(15)2020)
restore

* APPENDIX D
graph matrix mon_both_v70 mil_both_v70 op_both_v70 elecexw leg_rule2, half ms(p)   jitter(2) scheme(s2mono)
* Entries of correlation coefficients made by hand from:
pwcorr mon_both_v70 mil_both_v70 op_both_v70 elecexw leg_rule2, obs

*APPENDIX E
tempfile fil
preserve
  collapse e_regiongeo,by(country_id)
  save "`fil'"
restore
merge m:1 country_id using "`fil'", update
drop _merge
replace e_regiongeo=10 if country_name=="Saudi Arabia" & e_regiongeo==.
replace e_regiongeo=8 if country_name=="Zanzibar" & e_regiongeo==.
recode e_regiongeo (1 2 3 4=1) (5 6 7 8 9=2) (10 11 12 13 14 15=3) (16 17 18 19=4), gen(region)
replace region=1 if region==. & hist==1
label define region 1 "Europe" 2 "Africa" 3 "Asia" 4 "Americas"
label values region region
graph hbar mon_both_v70,over(region) yscale(r(0 1)) ylabel(#6) ytitle("Hereditary") name(mon_both_v70,replace) scheme(s2mono)
graph hbar mil_both_v70,over(region) yscale(r(0 1)) ylabel(#6) ytitle("Military") name(mil_both_v70,replace) scheme(s2mono)
graph hbar op_both_v70,over(region) yscale(r(0 1)) ylabel(#6) ytitle("Ruling party") name(op_both_v70,replace) scheme(s2mono)
graph hbar elecexw,over(region) yscale(r(0 1)) ylabel(#6) ytitle("Direct election") name(elecexw,replace) scheme(s2mono)
graph hbar leg_rule2,over(region) yscale(r(0 1)) ylabel(#6) ytitle("Confidence") name(leg_rule2,replace) scheme(s2mono)
graph combine op_both_v70 mil_both_v70 mon_both_v70 elecexw leg_rule2, rows(2) title("Regional averages") iscale(.5)

* APPENDIX F
* First collapsing the GWF categories according to their PoP-article footnote 19
recode gwf_regimetype (1=1) (2=2) (3 7 10=3) (4 5 6 8 9=4), gen(gwf)
label define gwf 1 "Monarchy" 2 "Personalist" 3 "Military" 4 "Party"
label values gwf gwf
graph hbar mon_both_v70 mil_both_v70  op_both_v70  elecexw leg_rule2 if gwf==1, ylabel(#11) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Monarchy") scheme(s2mono) name(gwf1, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if gwf==2, ylabel(#11) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Personalist") scheme(s2mono) name(gwf2, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if gwf==3, ylabel(#11) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Military") scheme(s2mono) name(gwf3, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if gwf==4, ylabel(#11) yscale(r(0 1)) ytitle("") legend(order(1 "Hereditary" 2 "Military" 3 "Ruling party" 4 "Direct election" 5 "Confidence") rows(1) size(medsmall) symx(*.4)) xsize(15) title("Party") scheme(s2mono) name(gwf4, replace)
grc1leg gwf1 gwf2 gwf3 gwf4,legendfrom(gwf4) cols(1) iscale(.5)

* APPENDIX G
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if numentry==0, ylabel(#11) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Regular entry") scheme(s2mono) name(arch0, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if numentry==1, ylabel(#11) yscale(r(0 1)) ytitle("") legend(off) xsize(15) title("Irregular entry") scheme(s2mono) name(arch1, replace)
graph hbar mon_both_v70 mil_both_v70  op_both_v70 elecexw leg_rule2 if numentry==2, ylabel(#11) yscale(r(0 1)) ytitle("") legend(order(1 "Hereditary" 2 "Military" 3 "Ruling party" 4 "Direct election" 5 "Confidence") rows(1) size(medsmall) symx(*.4)) xsize(15) title("Foreign imposition") scheme(s2mono) name(arch2, replace)
grc1leg arch0 arch1 arch2, legendfrom(arch2) cols(1) iscale(.5)

